<?php

namespace app\common\model;
use think\Model;
use think\Db;
/**
 * ============================================================================
 * DSMall多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 数据层模型
 */
class Casue extends Model {

    public $page_info;
    /**
     * 更换原因记录
     * @access public
     * @author csdeshang
     * @param type $condition 条件
     * @param type $page 分页
     * @param type $limit 限制
     * @param type $fields 字段reason_id
     * @return array
     */
    public function getReasonList($condition = array(), $page = '', $limit = '', $fields = '*') {
        $result_paginate = $this->field($fields)->where($condition)->order('sort asc,id desc')->paginate($page,false,['query' => request()->param()]);
        $this->page_info = $result_paginate;
        $result = $result_paginate->items();
        $result = ds_change_arraykey($result, 'id');
        return $result;
    }

        /**
     * 更换人员记录
     * @access public
     * @author csdeshang
     * @param type $condition 条件
     * @param type $page 分页
     * @param type $limit 限制
     * @param type $fields 字段reason_id
     * @return array
     */
    public function getChangeList($condition = array(), $page = '', $limit = '', $fields = '*') {
        $result_paginate = $this->field($fields)->where($condition)->order('sort asc,id desc')->paginate($page,false,['query' => request()->param()]);
        $this->page_info = $result_paginate;
        $result = $result_paginate->items();
        $result = ds_change_arraykey($result, 'id');
        return $result;
    }

    /**
     * 增加更换原因
     * @access public
     * @author csdeshang
     * @param type $reason_array 原因数组
     * @return type
     */
    public function addReason($reason_array) {
        $reason_id = db('casue')->insertGetId($reason_array);
        return $reason_id;
    }

    /**
     * 修改更换原因记录
     * @access public
     * @author csdeshang
     * @param type $condition 条件
     * @param type $data 数据
     * @return boolean
     */
    public function editReason($condition, $data) {
        if (empty($condition)) {
            return false;
        }
        if (is_array($data)) {
            $result = db('casue')->where($condition)->update($data);
            return $result;
        } else {
            return false;
        }
    }
}

?>
